#include <cstdio>
#include <cstring>
using namespace std;

const int maxlen = 100005;
int linked_list[maxlen], last, cur;
char str[maxlen];

int main() {
  while (scanf("%s", str + 1) == 1) {
    int str_len = strlen(str + 1);
    last = cur = 0;
    linked_list[0] = 0;
    /* debugging */
    // printf("last: %d\n", last);
    /* debugging */
    // printf("cur: %d\n", cur);
    /* debugging */
    // printf("linked_list[0]: %d\n", linked_list[0]);
    for (int i = 1; i <= str_len; i++) {
      /* debugging */
      //printf("i: %d\n", i);
      char c = str[i];
      /* debugging */
      //printf("c: %c\n", c);
      if (c == '[') {
        cur = 0;
      }
      else if (c == ']') {
        cur = last;
      }
      else {
        linked_list[i] = linked_list[cur];
        /* debugging */
        // printf("linked_list[%d(i)]: %d\n", i, linked_list[i]);
        linked_list[cur] = i;
        /* debugging */
        // printf("linked_list[%d(cur)]: %d\n", cur, linked_list[cur]);
        if (cur == last) {
          last = i;
        }
        cur = i;
        /* debugging */
        // printf("last: %d\n", last);
        /* debugging */
        // printf("cur: %d\n", cur);
      }
    }

    /* debugging */
    // for (int i = linked_list[0]; i != 0; i = linked_list[i]) {
    //   printf("%d ", i);
    // }
    // printf("\n");
    for (int i = linked_list[0]; i != 0; i = linked_list[i]) {
      printf("%c", str[i]);
    }
    printf("\n");
  }
  return 0;
}
